create or replace function idcard_getdate(p_IDcard varchar2) return integer is

IDcardlen integer;
IDcardate integer;

begin

  IDcardlen :=Length(trim(p_IDcard));

   if is_idcard(p_IDcard) and IDcardlen = 18 then
     IDcardate := to_number(substr(p_IDcard,7,8));
  end if;
  if is_idcard(p_IDcard) and IDcardlen = 15 then
     IDcardate := to_number('19'||substr(p_IDcard,7,6));
  end if;

  return IDcardate ;


end idcard_getdate;
/
